import java.util.Timer;
import java.util.TimerTask;

public class GameTimer {
    private Timer timer;
    private LifeGame lifeGame;
    private GameGUI gameGUI;

    public void init(LifeGame lifeGame, GameGUI gameGUI) {
        timer = new Timer();
        this.lifeGame = lifeGame;
        this.gameGUI = gameGUI;
    }

    public void start(long interval) {
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                lifeGame.gameCycle();
                gameGUI.updateMap();
            }
        }, 0, interval);
    }

    public void singleStep() {
        lifeGame.gameCycle();
    }

    public void stop() {
        timer.cancel();
    }

}
